﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YougeBookmark.Utilities
{
    public static class ToolByStatic
    {
        public static Stream BytesToStream(this byte[] bytes)
        {
            var stream = new MemoryStream(bytes);
            return stream;
        }

        public static System.Drawing.Image BytesToImage(this byte[] bytes)
        {
            using (var stream = new MemoryStream(bytes))
            {
                return Image.FromStream(stream);
            }
        }

        public static string GetDtStr(this DateTime dt, string strFormat = "yyyy-MM-dd HH:mm:ss")
        {
            return dt.ToString(strFormat);
        }
    }

    public class Tool
    {

        public static byte[] ConvertImageToByteArray(string relativePath)
        {
            try
            {
                // 拼接绝对路径
                string fullPath = Path.Combine(Application.StartupPath, relativePath);

                // 检查文件是否存在
                if (!File.Exists(fullPath))
                {
                    //MessageBox.Show("图片文件不存在！");
                    return null;
                }

                // 读取文件为 byte[]
                return File.ReadAllBytes(fullPath);
            }
            catch (Exception ex)
            {
                //MessageBox.Show($"错误: {ex.Message}");
                return null;
            }
        }
    }

}
